home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / Programming / MSTPChart / MenuControl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-26  |  3.6 KB  |  146 lines  |  [TEXT/KAHL]

  1. #include    "MST_Defines.h"
  2. #include    "MST_Externs.h"
  3. #include    "MST_Prototypes.h"
  4. #include    "MST_Menus.h"
  5.  
  6.  
  7. /*_____________________________________________________________________________
  8.                         Init-ApplicationMenus()- set up our initial menus
  9. _____________________________________________________________________________*/
  10.  
  11.  
  12.  
  13. void Init_ApplicationMenus() 
  14. {
  15.      MenuHandle    thisMenu,thatMenu;
  16. /*
  17. •        Our menus are straightforward and do not change during the course of the
  18. •        program's execution. Our task is further simplified by placing all our
  19. •        menu information in our menu resources (MENU). First we clear the menubar,
  20. •        then add the Apple, File, Edit, and our Chart menus, and finally draw
  21. •        the menubar. InsertMenu adds a menu to the menubar; a zero as the
  22. •        second parameter inserts it at the end. AddResMenu searches for all
  23. •        available resources of a particular type, and tacks them onto the end
  24. •        of a menu as menu items. So AddResMenu (thisMenu, 'DRVR') is how one adds
  25. •        all the Apple Menu Items (formerly desk accessories in system 6 talk...DRVR
  26. •        is the resource type for a desk accessory). Notice how even though Apple
  27. •        completely changed the concept of what appears under the Apple menu,
  28. •        the changes are transparent to your program. Pretty cool, eh?
  29. */
  30.     ClearMenuBar();
  31.  
  32.     thisMenu     = GetMenu    (Menu_Apple); 
  33.     InsertMenu    (thisMenu,0);
  34.     AddResMenu    (thisMenu,'DRVR'); 
  35.     
  36.     InsertMenu (GetMenu    (Menu_File),0);
  37.     InsertMenu (GetMenu    (Menu_Edit),0);
  38.     InsertMenu    (GetMenu(Menu_Chart),0);
  39.  
  40.     DrawMenuBar();
  41. }
  42.  
  43.  
  44. /*_____________________________________________________________________________
  45.                         Handle-TheMenus()- respond to menu choices
  46. _____________________________________________________________________________*/
  47.  
  48.  
  49.  
  50. void    Handle_TheMenus    (short thisMenu,short thisItem)
  51. {
  52.     Str255        thisName;
  53. /*
  54. •        Very straigtforward. Just keep checking for all the possibilities
  55. •        until you find the menu item selected, then take the appropriate action.
  56. */
  57.     switch (thisMenu)  
  58.     {
  59.         case    Menu_Apple: 
  60.         {
  61.             switch    (thisItem)
  62.             {
  63. /*
  64. •        If our About MacSciTech menu item was selected, then open our About Box.
  65. */
  66.                 case    Item_AboutMST:
  67.                 {
  68.                     Open_AboutMST();
  69.                     break;
  70.                 }
  71. /*
  72. •        Otherwise launch the Apple Menu Item selected. Note the call OpenDeskAcc()
  73. •        still works the same way under System 7.
  74. */
  75.                 default:
  76.                 {
  77.                     GetItem    (GetMenu(Menu_Apple),thisItem,&thisName);
  78.                     OpenDeskAcc    (thisName);
  79.                     break;
  80.                 }
  81.             }
  82.             break;
  83.         }
  84.         case    Menu_File: 
  85.         {
  86.             switch    (thisItem)
  87.             {
  88.                 case    Item_Quit:
  89.                 {
  90. /*
  91. •        We only have one item in the File menu: Quit. In most applications, you
  92. •        will have some tidying up to do, like asking if the user wants to save
  93. •        work to disk. A useful technique is to set Quitting to TRUE, and use it
  94. •        as a flag to stop handling null events normally, and instead start cleaning
  95. •        up. When cleaned up, then set a flag called Finished to TRUE, and use
  96. •        Finished as your test criterion in your main event loop.
  97. */
  98.                     Quitting    =    TRUE;
  99.                     break;
  100.                 }
  101.                 default:    break;
  102.             }
  103.             break;
  104.         }
  105.         case    Menu_Edit: 
  106.         {
  107. /*
  108. •        We don't handle any edit functions.
  109. */
  110.             break;
  111.         }
  112.         case    Menu_Chart:
  113.         {
  114.             switch    (thisItem)
  115.             {
  116. /*
  117. •        Open the Periodic Chart window if the Open item was selected under the Chart
  118. •        menu.
  119. */
  120.                 case    Item_OpenChart:
  121.                 {
  122.                     Open_PeriodicChart();
  123.                     break;
  124.                 }
  125. /*
  126. •        Or close it if the Close item was selected.
  127. */
  128.                 case    Item_CloseChart:
  129.                 {
  130.                     Close_PeriodicChart();
  131.                     break;
  132.                 }
  133.                 default:    break;
  134.             }
  135.             break;
  136.         }            
  137.     }
  138. /*
  139. •        Finally, you need to call HiliteMenu(0) in order to unhighlight the menu
  140. •        selected. (The call to MenuSelect() in the main event loop leaves the menu
  141. •        highlighted.)
  142. */
  143.     HiliteMenu(0);
  144. }
  145.  
  146.